package com.mtbu.bean.base;
import java.util.*;
import java.text.SimpleDateFormat;
import org.json.JSONObject;
import my.json.core.JsonAble;
public abstract class CommonCfgBase implements JsonAble {
    private Map<String, Object> dirtyProperties = new HashMap<String, Object>();
    //
    private int id = 0;
    //
    private String cfgKey = "";
    //
    private String value = "";
    //
    private Date updateTime = null;
    public int getId(){
        return this.id;
    }
    public void setId(int id){
        this.id = id;
    }
    public String getCfgKey(){
        return this.cfgKey;
    }
    public void setCfgKey(String cfgKey){
        this.cfgKey = cfgKey;
        dirtyProperties.put("cfgKey", cfgKey);
    }
    public String getValue(){
        return this.value;
    }
    public void setValue(String value){
        this.value = value;
        dirtyProperties.put("value", value);
    }
    public Date getUpdateTime(){
        return this.updateTime;
    }
    public String getUpdateTime_ToDateString(){
        if(updateTime==null) return "";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(this.updateTime);
    }
    public String getUpdateTime_ToTimeString(){
        if(updateTime==null) return "";
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return formatter.format(this.updateTime);
    }
    public String getUpdateTime_ToDateTimeString(){
        if(updateTime==null)   return "";
        SimpleDateFormat   formatter   =   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(this.updateTime);
    }
    public void setUpdateTime(Date updateTime){
        this.updateTime = updateTime;
        dirtyProperties.put("updateTime", updateTime);
    }
    public Map<String, Object> getDirtyProperties() {
        return this.dirtyProperties;
    }
    public JSONObject toJSON() throws Exception {
        JSONObject json = new JSONObject();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        json.put("id", this.getId());
        if(cfgKey!=null){
           json.put("cfgKey",this.getCfgKey());
        }
        if(value!=null){
           json.put("value",this.getValue());
        }
        if(updateTime!=null){
            json.put("updateTime",formatter.format(this.getUpdateTime()));
        }
        return json;
    }
    public void fromJSON(JSONObject json) throws Exception {
        if(json==null) return;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try{
            if(json.get("id") != null){
                this.setId(Integer.parseInt(json.get("id")+""));
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("cfgKey") != null){
                this.setCfgKey(json.get("cfgKey")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("value") != null){
                this.setValue(json.get("value")+"");
            }
        }catch(Exception ex){
        }
        try{
            if(json.get("updateTime") != null){
                this.setUpdateTime(formatter.parse(json.get("updateTime")+""));
            }
        }catch(Exception ex){
        }
    }
    public void fromMap(Map<String, String> json) throws Exception {
        if(json==null) return;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if(json.containsKey("id".toLowerCase())){
                this.setId(Integer.parseInt(json.get("id".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("cfgKey".toLowerCase())){
                this.setCfgKey(json.get("cfgKey".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("value".toLowerCase())){
                this.setValue(json.get("value".toLowerCase())+"");
            }
        }catch(Exception ex){
        }
        try {
            if(json.containsKey("updateTime".toLowerCase())){
                this.setUpdateTime(formatter.parse(json.get("updateTime".toLowerCase())+""));
            }
        }catch(Exception ex){
        }
    }
}
